package com.zzyy.study.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzyy.study.entities.User;
import com.zzyy.study.mapper.UserMapper;
import com.zzyy.study.service.UserTXService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @auther zzyy
 * @create 2024-07-03 15:38
 */
@Service(value = "userTXServiceB")
public class UserTXServiceImplB extends ServiceImpl<UserMapper, User> implements UserTXService
{
    @Resource
    private UserMapper userMapper;

    @Override
    @Transactional
    public boolean addtx(User user)
    {
        //1 新增
        userMapper.insert(user);
        System.out.println("UserTXServiceImplB刚刚新增完entity的主键: "+user.getId()+"\t性别: "+user.getSex());

        //2 修改新增记录的性别
        user.setSex(3);
        this.updateSex(user);

        return true;
    }

    public void updateSex(User user)
    {
        userMapper.updateById(user);
    }
}
